package methodcite;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class Practice {
    public static void main(String[] args) {
//        practice01();
//        practice02();
        practice03();
    }
    public static void practice01(){
        // 集合中存储一些字符串的数据比如:张三,23 收集到Student类型数组当中
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list,"小平-23","小同-25");
        Student[] collect = list.stream().map(Student::new).toArray(Student[]::new);
        System.out.println(Arrays.toString(collect));

    }
    public static void practice02(){
        // 创造集合添加学生对象，学生对象属性：name，age，只获取姓名并放到数组当中
        Student s1 = new Student("小平",18);
        Student s2 = new Student("小美",19);
        Student s3 = new Student("小同",20);
        ArrayList<Student> list = new ArrayList<>();
        Collections.addAll(list,s1,s2,s3);
        String[] collect = list.stream().map(Student::getName).toArray(String[]::new);
        System.out.println(Arrays.toString(collect));
    }
    public static void practice03(){
        // 创造集合添加学生对象，学生对象属性：name，age，、
        // 把姓名和年龄拼接成，张三-23的字符串，并放到数组当中
        Student s1 = new Student("小平",18);
        Student s2 = new Student("小美",19);
        Student s3 = new Student("小同",20);
        ArrayList<Student> list = new ArrayList<>();
        Collections.addAll(list,s1,s2,s3);
        String[] collect = list.stream().map(Student::joinString).toArray(String[]::new);
        System.out.println(Arrays.toString(collect));
    }
}
